package com.yuexunit.application.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import com.yuexunit.persist.annotation.Cacheable;
import com.yuexunit.util.DateUtil;
import com.yuexunit.util.UuidUtil;


/**
 * 应用信息
 * @author wangjinshui
 */
@Entity
@Table(name="AP_APP")
@Cacheable(maxCount=5000, timeToIdleSeconds=36000)
public class ApplicationEntity {
	@Id
	@GeneratedValue
	@Column(name="APP_ID")
	private Long applicationId;
	
	@Column(name="APP_NAME")
	private String name;

	@Column(name="APP_TYPE")
	private String type;
	
	@Column(name="APP_PLATFORM")
	@Enumerated(EnumType.ORDINAL)
	private PlatformEnum platform;
	
	@Column(name="APP_KEY")
	private String key;
	
	@Column(name="DIRECTOR")
	private String director;

	@Column(name="APP_DESC")
	private String description;

	@Column(name="LATEST_FORCED_VERSION")
	private String latestForcedVersion;
	
	@Column(name="LATEST_VERSION")
	private String latestVersion;
	
	@Column(name="ENABLED")
	private Boolean enabled;

	@Column(name="UPDATE_DT")
	private Date updateDate;

	
	public ApplicationEntity() {
	}
	
	public ApplicationEntity(String name, String type, PlatformEnum platform, String director, String description) {
		this.name = name;
		this.type = type;
		this.platform = platform;
		this.director = director;
		this.description = description;
		
		this.key = UuidUtil.randomUUID();
		this.enabled = Boolean.TRUE;
		this.updateDate = DateUtil.now();
	}
	

	public Long getApplicationId() {
		return applicationId;
	}

	public void setApplicationId(Long applicationId) {
		this.applicationId = applicationId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public PlatformEnum getPlatform() {
		return platform;
	}

	public void setPlatform(PlatformEnum platform) {
		this.platform = platform;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getDirector() {
		return director;
	}

	public void setDirector(String director) {
		this.director = director;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getLatestForcedVersion() {
		return latestForcedVersion;
	}

	public void setLatestForcedVersion(String latestForcedVersion) {
		this.latestForcedVersion = latestForcedVersion;
	}

	public String getLatestVersion() {
		return latestVersion;
	}

	public void setLatestVersion(String latestVersion) {
		this.latestVersion = latestVersion;
	}

	public Boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(Boolean enabled) {
		this.enabled = enabled;
	}

	public Date getUpdateDate() {
		return updateDate;
	}

	public void setUpdateDate(Date updateDate) {
		this.updateDate = updateDate;
	}
	
	
	@Override
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		result.append(getClass().getName())
			.append(": applicationId=").append(applicationId)
			.append(", name='").append(name).append("'")
			.append(", type='").append(type).append("'")
			.append(", platform=").append(platform)
			.append(", key='").append(key).append("'")
			.append(", director='").append(director).append("'")
			.append(", description='").append(description).append("'")
			.append(", latestForcedVersion='").append(latestForcedVersion).append("'")
			.append(", latestVersion='").append(latestVersion).append("'")
			.append(", enabled=").append(enabled)
			.append(", updateDate=").append(updateDate)
			;
		
		return result.toString();
	}
}
